home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMIBEST2.ADF / Best of AMICUS 2 / C / SkinnyC / Listing3.c < prev    next >
C/C++ Source or Header  |  1987-07-22  |  3KB  |  112 lines

  1. /******************************************************
  2. * REQUEST - A simple boolean requester command for use
  3. *           within EXECUTE command files.
  4. *******************************************************
  5. * BVO Computing Services, January 1987, Bob Riemersma
  6. *******************************************************
  7. * Format:   REQUEST <string>
  8. * Template: REQUEST " "
  9. * Purpose:  To ask the user a yes/no question from
  10. *           within an EXECUTE command file.
  11. * Specification:
  12. *   REQUEST invokes a system requester displaying the
  13. *   text argument given, and accepts either a "Yes" or
  14. *   a"No" response via the requester's boolean gadgets.
  15. *   This response is communicated to the command stream
  16. *   via REQUEST's return result: 0 = No, 5 = Yes.
  17. * Example:
  18. *           REQUEST "Are you older than 35?"
  19. *           IF WARN  ;WARN = Yes
  20. *              ECHO "Hmmm, so you are."
  21. *           ELSE
  22. *              ECHO "Just a young whippersnapper!"
  23. *           ENDIF
  24. *******************************************************
  25. * Note to rodent-haters:
  26. *   Beginning with KS/WB 1.2 you may respond using
  27. *   "Left Amiga-V" for "Yes", "Left Amiga-B" for "No".
  28. ******************************************************/
  29. #include <exec/types.h>
  30. #include <libraries/dosextens.h>
  31. #include <intuition/intuition.h>
  32. struct IntuitionBase *IntuitionBase;
  33. #define INTUITION_REV 0
  34.  
  35. struct IntuiText Question =
  36. {
  37.    2, 1,          /* FrontPen, BackPen */
  38.    JAM1,
  39.    8, 6,          /* LeftEdge, TopEdge */
  40.    NULL,          /* Use default font */
  41.    NULL,          /* IText, filled at runtime */
  42.    NULL           /* No linked IntuiTexts */
  43. },
  44.                  Positive =
  45. {
  46.    2, 1,
  47.    JAM1,
  48.    6, 4,
  49.    NULL,
  50.    "Yes",
  51.    NULL
  52. },
  53.                  Negative =
  54. {
  55.    2, 1,
  56.    JAM1,
  57.    6, 4,
  58.    NULL,
  59.    "No",
  60.    NULL
  61. };
  62.  
  63. #define Me 0
  64. extern struct Process *FindTask();
  65. struct Process *Myself;
  66.  
  67. extern BOOL AutoRequest();
  68.  
  69. _main(CommandLine)
  70.    UBYTE *CommandLine;
  71. {
  72.    int QuestionChars,
  73.        ReqWidth;
  74.    BOOL Yes;
  75.  
  76.    /* Scan CommandLine for first quote */
  77.    while (*CommandLine != '\0' && *CommandLine != '"')
  78.       CommandLine++;
  79.    if (*CommandLine == '\0')
  80.       _exit(120);
  81.  
  82.    /* Skip quote & store ptr, scan to final quote (counting
  83.     * chars), '\0' it to terminate the IText string.        */
  84.    Question.IText = ++CommandLine;
  85.    QuestionChars = 0;
  86.    while (*CommandLine != '\0' && *CommandLine != '"')
  87.    {
  88.       CommandLine++;
  89.       QuestionChars++;
  90.    }
  91.    if (*CommandLine == '\0')
  92.       _exit(120);
  93.    *CommandLine = '\0';
  94.  
  95.    IntuitionBase = (struct IntuitionBase *)
  96.                    OpenLibrary("intuition.library", INTUITION_REV);
  97.    if (IntuitionBase == NULL)
  98.       _exit(FALSE);
  99.  
  100.    Myself = FindTask(Me);
  101.  
  102.    if ((ReqWidth = 8*QuestionChars+40) < 200)
  103.       ReqWidth = 200;
  104.    Yes = AutoRequest(Myself->pr_WindowPtr,            /* Console Window */
  105.                      &Question, &Positive, &Negative, /* IntuiTexts */
  106.                      NULL, NULL,                      /* No extern. events */
  107.                      ReqWidth, 50);                   /* Width, Height */
  108.  
  109.    CloseLibrary(IntuitionBase);
  110.    _exit((Yes) ? 5 : 0);
  111. }
  112.